package com.information.manage.basic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.model.entity.DictionaryCategoryDO;
import com.information.manage.basic.model.query.AddDictionaryCategoryQuery;
import com.information.manage.basic.model.query.DictPageQuery;
import com.information.manage.basic.model.vo.DictionaryCategoryListVO;
import com.information.manage.basic.common.result.Result;
import com.information.manage.basic.service.DictionaryCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "字典类型")
@RestController
@RequestMapping("/dictionary/category")
public class DictionaryCategoryController {

    @Resource
    private DictionaryCategoryService dictionaryCategoryService;

    @GetMapping("/list")
    @ApiOperation(value = "获取字典列表", notes = "获取字典列表")
    public Result<List<DictionaryCategoryListVO>> queryDictionaryCategoryList(String name){
        return Result.ok(dictionaryCategoryService.queryDictionaryCategoryList(name));
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加字典分类", notes = "添加字典分类")
    public Result<Long> add(@RequestBody AddDictionaryCategoryQuery addDictionaryCategoryQuery){
        return dictionaryCategoryService.add(addDictionaryCategoryQuery);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询字典", notes = "分页查询字典")
    public Result<Page<DictionaryCategoryDO>> queryStaffPage(DictPageQuery dictPageQuery) {
        return dictionaryCategoryService.queryDictPage(dictPageQuery);
    }

    @GetMapping("/find/{id}")
    @ApiOperation(value = "查询字典", notes = "查询字典")
    public Result<DictionaryCategoryDO> findDictById(@PathVariable("id") int id) {
        return Result.ok(dictionaryCategoryService.getById(id));
    }
    @PostMapping("/update")
    @ApiOperation(value = "修改字典", notes = "修改字典")
    public Result<Boolean> updateUser(@RequestBody DictionaryCategoryDO dictionaryCategoryDO){
        return Result.ok(dictionaryCategoryService.updateById(dictionaryCategoryDO));
    }
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除字典", notes = "删除字典")
    public Result<Boolean> deleteUser(@PathVariable("id") int id){
        return Result.ok(dictionaryCategoryService.removeById(id));
    }

}
